import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import ClientProviders from '@/components/ClientProviders';
import RouteTransition from '@/components/RouteTransition';
import { LoadingProvider } from '@/components/CustomLink';
import { headers } from 'next/headers';
import Script from 'next/script';
import './globals.css';

const geistSans = Geist({
	variable: '--font-geist-sans',
	subsets: ['latin'],
});

const geistMono = Geist_Mono({
	variable: '--font-geist-mono',
	subsets: ['latin'],
});

export const metadata: Metadata = {
	title: 'Create Next App',
	description: 'Generated by create next app',
};

export default async function RootLayout({
	children,
}: Readonly<{
	children: React.ReactNode;
}>) {
	// 在组件顶层直接使用headers()
	const headersObj = await headers();
	const nonce = headersObj.get('x-nonce') || '';
	console.log('client-nonce:', nonce);
	return (
		<html lang="zh-cn">
			<body
			className={`${geistSans.variable} ${geistMono.variable} antialiased h-screen`}
		>
			<Script strategy="afterInteractive" nonce={nonce} src="..." />
			<ClientProviders>
				<LoadingProvider>
					<RouteTransition>{children}</RouteTransition>
				</LoadingProvider>
			</ClientProviders>
		</body>
		</html>
	);
}